package com.gitee.wsl.func.filter.sample

import kotlin.test.Test
import kotlin.test.assertFailsWith
import kotlin.test.assertTrue


class BloomFilterTests {
    @Test
    fun `do not empty string`() {
        val bloomFilter2 = BloomFilter2()
        assertFailsWith<IllegalArgumentException> { bloomFilter2.add("") }
    }

    @Test
    fun `add known word accepts non empty string`() {
        val bloomFilter2 = BloomFilter2()
        bloomFilter2.add("abc")
    }

//    @Test
//    fun `filter recognizes known word`() {
//        val hashAlgorithm = mockk<HashAlgorithm>()
//        every { hashAlgorithm.hash("abc") } returns 2
//
//        val bloomFilter = BloomFilter(1024, hashAlgorithm)
//        bloomFilter.add("abc")
//
//        assertTrue(bloomFilter.isProbablyKnown("abc"))
//    }

    private  val total = 100000 //测试元素的总数
    @Test
    fun `filter rejects unknown word`() {
//        val hashAlgorithm = mockk<HashAlgorithm>()
//        every { hashAlgorithm.hash("abc") } returns 2
//        every { hashAlgorithm.hash("cba") } returns 1

        val bloomFilter2 = BloomFilter<String>(0.01,total)
        bloomFilter2.add("abc")
        bloomFilter2.add("cba")
        val cba = bloomFilter2.contains("cba")
        assertTrue(cba)
    }
}